package com.server;

import org.apache.shiro.authc.AccountException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tools.SecuityUtils;

@Service
@RequestMapping("/login")
public class Login {
	@RequestMapping(value="/login.do",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String login(String username, String password){
		System.out.println(username+" : "+password);
		Subject subject = SecuityUtils.subject();
		UsernamePasswordToken token = new UsernamePasswordToken(username, password);
		String errType = "ok";
		try {
			subject.login(token);
		} catch (UnknownAccountException e) {
			errType = "用户名错误";
			
		} catch (IncorrectCredentialsException e) {
			errType = "密码错误";
			
		}catch (AccountException e) {
			errType = "其他错误";
		}
		return errType;
	}
	
	@RequestMapping("/bbbb")
	@ResponseBody
	public String admin(){
		return "123456";
	}
	
	@RequestMapping("/test1")
	@ResponseBody
	public String test1(){
		return "test1";
	}
	
	@RequestMapping("/test2")
	@ResponseBody
	public String test2(){
		return "test2";
	}
}
